<template>
  <div class="app-container">
    <div v-show="!show.detailShow">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="名称" prop="fProjectname">
          <el-select v-model="queryParams.fProjectname" placeholder="请选择版本号" clearable>
            <el-option
              v-for="dict in projectNames"
              :key="dict"
              :label="dict"
              :value="dict"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="版本号" prop="fStatusname">
          <el-select v-model="queryParams.fStatusname" placeholder="请选择版本号" clearable>
            <el-option
              v-for="dict in taskStatus"
              :key="dict"
              :label="dict"
              :value="dict"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="备注信息" prop="fStatusname">
          <el-select v-model="queryParams.fStatusname" placeholder="请选择备注信息" clearable>
            <el-option
              v-for="dict in taskStatus"
              :key="dict"
              :label="dict"
              :value="dict"
            />
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['system:survey:add']"
          >新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['system:survey:edit']"
          >修改</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['system:survey:remove']"
          >删除</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
          >导出</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="surveyList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="编号" align="center" prop="tucengid" />
        <el-table-column label="名称" align="center" prop="sn" />
        <el-table-column label="版本号" align="center" prop="bumen" />
        <el-table-column label="备注信息" align="center" prop="xinghao" />
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <taskDetail v-if="show.detailShow" ref="detail" :show="show"></taskDetail>
    <!-- 添加或修改调查列对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <el-form-item label="名称" prop="sn">
          <el-input v-model="form.fWyUserid" placeholder="请输入SN码" />
        </el-form-item>
        <el-form-item label="版本号" prop="bumen">
          <el-input v-model="form.fNyUserid" placeholder="请输入用户所属部门" />
        </el-form-item>
        <el-form-item label="备注信息" prop="xinghao">
          <el-input v-model="form.fXzqdm" type="textarea" placeholder="请输入设备型号" />
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSurveyStatus,listSurveyProjects,listSurvey, getSurvey, delSurvey, addSurvey, updateSurvey } from "@/api/survey/survey";
import taskDetail from '@/views/survey/task/taskDetail'

export default {
  name: "sblxgl",
  components: {taskDetail},
  data() {
    return {
      // 遮罩层
      loading: true,
      projectNames:[],
      taskStatus:[],
      show:{
        detailShow:false,
      },
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 调查列表格数据
      surveyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fLayerid: null,
        fProjectname:null,
        fWyUserid: null,
        fNyUserid: null,
        fXzqdm: null,
        fStatusid: null,
        fStatusname:null,
        fFeatureid: null,
        fSurveymedia: null,
        fSurveyprop: null,
        fSurveydesc: null,
        fReviewdesc: null,
        fSurveytime: null,
        fReviewtime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        fFeatureid: [
          { required: true, message: "要素唯一标识不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getProjectList();
  },
  methods: {
    /** 查询调查列列表 */
    getProjectList() {
      let that = this;
      listSurveyProjects().then(response => {
        let projects = response.rows;
        that.projectNames = [];
        for (let i in projects) {
          if(that.projectNames.indexOf(projects[i].f_projectname)==-1){
            that.projectNames.push(projects[i].f_projectname);
          }
        }
      });
      listSurveyStatus().then(response => {
        let status = response.rows;
        that.taskStatus = [];
        for (let i in status) {
          if(that.taskStatus.indexOf(status[i].f_statusname)==-1){
            that.taskStatus.push(status[i].f_statusname);
          }
        }
      });
    },
    getList() {
      let that=this;
      //  that.loading = true;
      that.surveyList =[
        {tucengid:"1",sn:"OnePlus LE2100",bumen:"V12.1",xinghao:"OnePlus",renyuan:"安达外业1",ruku:"2022-05-21",zhuangtai:"在用"},
        {tucengid:"2",sn:"Hover20c3",bumen:"12",xinghao:"Hover",renyuan:"北林外业1",ruku:"2022-09-01",zhuangtai:"在用"},
        {tucengid:"3",sn:"HUAWEIABR",bumen:"V11",xinghao:"HUAWEI",renyuan:"李伟",ruku:"2022-10-06",zhuangtai:"在用"},
      ];
      that.total = 3;
      that.loading = false;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        fSurveyid: null,
        fLayerid: null,
        fWyUserid: null,
        fNyUserid: null,
        fXzqdm: null,
        fStatusid: null,
        fFeatureid: null,
        fSurveymedia: null,
        fSurveyprop: null,
        fSurveydesc: null,
        fReviewdesc: null,
        fSurveytime: null,
        fReviewtime: null
      };
      //  this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.fSurveyid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加设备类型信息";
    },
    //查看项目详情
    handleDetails(row) {
      this.show.detailShow=true;
      this.currentPro = row
      this.detailDialogOpen = true
      this.dialogTitle=row.xmmc;
      this.$nextTick(() => {
          this.$refs.detail.getCurrentProDetails(this.currentPro)
        }
      )
    },
    /** 修改按钮操作 ，现在没有用*/
    handleUpdate(row) {
      let that=this;
      //2022年11月24日 LQ 审核，本身是修改，现在没啥修改的，改为审核为了验收
      this.$confirm('是否通过审核？ ！', '警告', {
        confirmButtonText: '通过',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        //  that.reset();
        let ssform={
          fStatusid:4,
          fSurveyid:row.fSurveyid
        };
        updateSurvey(ssform).then(response => {
          that.$modal.msgSuccess("修改成功");
          that.open = false;
          that.getList();
        });
        // that.showAdd.showcp = false
        // that.showAdd.showcp = false
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.fSurveyid != null) {
            updateSurvey(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSurvey(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const fSurveyids = row.fSurveyid || this.ids;
      this.$modal.confirm('是否确认删除调查列编号为"' + fSurveyids + '"的数据项？').then(function() {
        return delSurvey(fSurveyids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('survey/export', {
        ...this.queryParams
      }, `survey_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
